#define ASM 1

#include <multiboot.h>

	.code32
	.text 
	.globl start, _start

start:
_start:
	jmp multiboot_entry
	
	.align 4 			# Align 32 bits boundary.
multiboot_header:
	/* magic */
	.long   MULTIBOOT_HEADER_MAGIC
	/* flags */
	.long   MULTIBOOT_HEADER_FLAGS
	/* checksum */
	.long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#ifndef __ELF__
	/* header_addr */
    .long   multiboot_header
	/* load_addr */
	.long   _start
	/* load_end_addr */
    .long   _edata
	/* bss_end_addr */
    .long   _end
    /* entry_addr */
	.long   multiboot_entry
#endif /* ! __ELF__ */

multiboot_entry:

	cli
	/* Initialize the stack pointer. */
	movl    $(stack + STACK_SIZE), %esp
     
    /* Reset EFLAGS. */
	pushl   $0
	popf

	pushl	$one_segment_gdt
	call	gdtMakeOneSegmentTable
	lgdt	one_segment_gdt

	lidt	fake_idt

	pushw	$8
	pop		%fs
//	movl	$0xEBAA,	%fs:0
//	pushl	%fs:0

	pushl	$(multiboot_entry)
	pushl	$(multiboot_header)
	pushl 	$(start)
	pushl	$(cmain)
	pushl   %ebx
	pushl   %eax
	call    EXT_C(cmain)

	

loop:
	hlt
	jmp loop

keyboard_handler:
	pushw	$0x58
	call	EXT_C(putchar)
	iret

fake_idt:
	.long 0,0,0,0,0,0,0,0,0,0,0

one_segment_gdt:
	.long 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	/* Our stack area. */
	.comm   stack, STACK_SIZE
